<?

session_start();
$soporte=$_SESSION['caweb']['soporte'];
require_once "../funciones.php";

################################################################################
##              -= YOU MAY NOT REMOVE OR CHANGE THIS NOTICE =-                 #
## --------------------------------------------------------------------------- #
##  PHP DataGrid version 4.2.8 (01.10.2008)                                    #
##  Author & developer:     Leumas Naypoka <leumas.a@gmail.com>                #
##  Developers:             Zewa           <http://www.softic.at>              #
##                          Fcallez        <http://www.innovavirtual.org>      #
##  Lisence:    GNU GPL                                                        #
##  Site:       http://phpbuilder.blogspot.com                                 #
##  Copyright:  Leumas Naypoka (c) 2006-2008. All rights reserved.             #

################################################################################   
## +---------------------------------------------------------------------------+
## | 1. Creating & Calling:                                                    | 
## +---------------------------------------------------------------------------+
##  *** only relative (virtual) path (to the current document)

  define ("DATAGRID_DIR", "");                     /* Ex.: "datagrid/" */ 
  define ("PEAR_DIR", "pear/");                    /* Ex.: "datagrid/pear/" */

  require_once(DATAGRID_DIR.'datagrid.class.php');
  require_once(PEAR_DIR.'PEAR.php');
  require_once(PEAR_DIR.'DB.php');

##  *** creating variables that we need for database connection 
  $DB_USER='caweb';
  $DB_PASS='caweb';
  $DB_HOST='localhost';
  $DB_NAME=$_SESSION['caweb']['basededatos'];

  ob_start();
##  *** (example of ODBC connection string)
##  *** $result_conn = $db_conn->connect(DB::parseDSN('odbc://root:12345@test_db'));
##  *** (example of Oracle connection string)
##  *** $result_conn = $db_conn->connect(DB::parseDSN('oci8://root:12345@localhost:1521/mydatabase)); 
##  *** (example of PostgreSQL connection string)
##  *** $result_conn = $db_conn->connect(DB::parseDSN('pgsql://root:12345@localhost/mydatabase)); 
##  === (Examples of connections to other db types see in "docs/pear/" folder)

  $db_conn = DB::factory('mysql');  /* don't forget to change on appropriate db type */
  $result_conn = $db_conn->connect(DB::parseDSN('mysql://'.$DB_USER.':'.$DB_PASS.'@'.$DB_HOST.'/'.$DB_NAME));
  if(DB::isError($result_conn)){ die($result_conn->getDebugInfo()); }  
##  *** put a primary key on the first place 

$usuario=$_SESSION['caweb']['username'];

if ($_POST[primeravez]==1)
{
    if($_POST[operador]=='OR' AND ($_POST[tipobusqueda2]=="ITEM" OR $_POST[tipobusqueda2]=="EMPIEZA" OR $_POST[tipobusqueda2]=="CONTIENE" OR $_POST[tipobusqueda2]=="NOCONTIENE") AND $_POST[busqueda2]<>"" AND $_POST[busqueda2]<>"XXX") 
        { $parentesis1='('; $parentesis2=')'; } else { $parentesis1=''; $parentesis2=''; }
    
	$caracteres=strlen($_POST[claseitem]);
	$condicion=" AND bodega<>'BAJ' AND bodega<>'TER' ";
	if ($_POST[sucursal]<>"XXX") $condicion.=" AND sucursalcontrol='$_POST[sucursal]'"; else  $condicion.="";
	if ($_POST[claseitem]<>"XXX") $condicion.=" AND LEFT(item,$caracteres)='$_POST[claseitem]'"; else  $condicion.="";
    
	if ($_POST[tipobusqueda]=="ITEM" AND $_POST[busqueda]<>"XXX")  $condicion.=" AND $parentesis1 item='$_POST[busqueda]'"; else  $condicion.="";
	if ($_POST[tipobusqueda]=="EMPIEZA" AND $_POST[busqueda]<>"")  $condicion.=" AND $parentesis1 item LIKE '$_POST[busqueda]%'"; else  $condicion.="";
	if ($_POST[tipobusqueda]=="CONTIENE" AND $_POST[busqueda]<>"")  $condicion.=" AND $parentesis1 item LIKE '%$_POST[busqueda]%'"; else  $condicion.="";
    if ($_POST[tipobusqueda]=="NOCONTIENE" AND $_POST[busqueda]<>"")  $condicion.=" AND $parentesis1 item NOT LIKE '%$_POST[busqueda]%'"; else  $condicion.="";
    
    if ($_POST[tipobusqueda2]=="ITEM" AND $_POST[busqueda2]<>"XXX")  $condicion.=" $_POST[operador] item='$_POST[busqueda2]' $parentesis2"; else  $condicion.="";
	if ($_POST[tipobusqueda2]=="EMPIEZA" AND $_POST[busqueda2]<>"")  $condicion.=" $_POST[operador] item LIKE '$_POST[busqueda2]%' $parentesis2"; else  $condicion.="";
	if ($_POST[tipobusqueda2]=="CONTIENE" AND $_POST[busqueda2]<>"")  $condicion.=" $_POST[operador] item LIKE '%$_POST[busqueda2]%' $parentesis2"; else  $condicion.="";
    if ($_POST[tipobusqueda2]=="NOCONTIENE" AND $_POST[busqueda2]<>"")  $condicion.=" $_POST[operador] item NOT LIKE '%$_POST[busqueda2]%' $parentesis2"; else  $condicion.="";
    
	if ($_POST[bodega]<>"XXX") $condicion.=" AND bodega='$_POST[bodega]'"; else  $condicion.="";

    if ($_POST[bodegaexcluida1]<>"XXX") $condicion.=" AND bodega <> '$_POST[bodegaexcluida1]'"; else  $condicion.="";
    if ($_POST[bodegaexcluida2]<>"XXX") $condicion.=" AND bodega <> '$_POST[bodegaexcluida2]'"; else  $condicion.="";
    if ($_POST[bodegaexcluida3]<>"XXX") $condicion.=" AND bodega <> '$_POST[bodegaexcluida3]'"; else  $condicion.="";
    
	if ($_POST[ubicacion]<>"XXX" AND $_POST[ubicacion]<>"") $condicion.=" AND ubicacion='$_POST[ubicacion]'"; else $condicion.="";
	if ($_POST[calidad]<>"XXX") $condicion.=" AND calidad='$_POST[calidad]'"; else  $condicion.="";
	if ($_POST[estado]<>"XXX") $condicion.=" AND estado='$_POST[estado]'"; else  $condicion.="";
    
	$_SESSION['caweb']['condicion']=$condicion;
	$_SESSION['caweb']['tiporeporte']=$_POST[tiporeporte];


	if ($_SESSION['caweb']['tiporeporte']=="R")
	{
	        $link32 = con_caweb();

		$result32 ="DELETE FROM temporal_coninvres WHERE usuario='$usuario'";
		$result32=mysql_query($result32,$link32) or die('Error temporal_coninvres, '.mysql_error());

	        $result32 ="INSERT INTO temporal_coninvres (usuario,item,descripcion,cantidad)
            	        SELECT
            	        '$usuario'              AS usuario,
            	        seriales.item           AS item,
            	        tax.taxDesc       AS descripcion,
            	        COUNT(seriales.item)    AS cantidad
            	        FROM
            	        seriales
                	INNER JOIN intranetpccom.taxonomia tax ON tax.codigotaxonomia = seriales.item WHERE 1=1 $condicion GROUP BY item";
	        $result32=mysql_query($result32,$link32) or die('Error temporal_coninvres, '.mysql_error());
	}
}
else
{
	$condicion=$_SESSION['caweb']['condicion'];
}

if ($_SESSION['caweb']['tiporeporte']=="D")
{
    $sql ="
    SELECT
    seriales.interno        	AS interno,
    seriales.ultimomovimiento  	AS ultimomovimiento,
    seriales.fechainstalacion  	AS fechainstalacion,
    seriales.item           	AS item,
    seriales.ciudad           	AS ciudad,
    tax.taxDesc       	AS descripcion,
    seriales.serial         	AS serial,
	seriales.memoria			AS memoria,
	seriales.disco				AS disco,
	seriales.video				AS video,
	seriales.red				AS red,
	seriales.opticos			AS optico,
    seriales.estado         	AS estado,
	seriales.pedido         	AS pedido,
    seriales.calidad        	AS calidad,
	seriales.tarifa        		AS tarifa,
    seriales.sucursalcontrol 	AS sucursal,
    seriales.bodega         	AS bodega,
    seriales.ubicacion      	AS ubicacion,
    seriales.marca          	AS marca,
    seriales.modelo         	AS modelo,
IF(seriales.bodega='GRA',(SELECT proveedores.nombre FROM proveedores WHERE proveedores.nit=seriales.ubicacion LIMIT 1),
IF(seriales.bodega='TEC' OR seriales.bodega='ALI' OR seriales.bodega='LAB',(SELECT intranetpccom.usuarios.nombres FROM intranetpccom.usuarios WHERE intranetpccom.usuarios.cedula=seriales.ubicacion LIMIT 1),
IF(seriales.bodega='CLI' OR seriales.bodega='ACA' OR seriales.bodega='TRA',(SELECT $soporte.mantis_project_table.name FROM $soporte.mantis_project_table WHERE $soporte.mantis_project_table.nit=seriales.ubicacion LIMIT 1),'No Disponible'))) AS nombre
    FROM
    seriales
    LEFT JOIN intranetpccom.taxonomia tax ON tax.codigotaxonomia = seriales.item
    WHERE 1=1 $condicion";
}

if ($_SESSION['caweb']['tiporeporte']=="R")
{
	$sql ="
        SELECT
        item          AS item,
        descripcion   AS descripcion,
		cantidad      AS cantidad
        FROM
        temporal_coninvres
	WHERE usuario='$usuario'";
}


##  *** set needed options and create a new class instance 
  $debug_mode = false;        /* display SQL statements while processing */    
  $messaging = true;          /* display system messages on a screen */ 
  $unique_prefix = "f_";    /* prevent overlays - must be started with a letter */
  $dgrid = new DataGrid($debug_mode, $messaging, $unique_prefix, DATAGRID_DIR);
##  *** set data source with needed options
  $default_order_field = "item";
  $default_order_type = "ASC";
  $dgrid->dataSource($db_conn, $sql, $default_order_field, $default_order_type);	    
##
##
## +---------------------------------------------------------------------------+
## | 2. General Settings:                                                      | 
## +---------------------------------------------------------------------------+
##  *** set encoding and collation (default: utf8/utf8_unicode_ci)
 $dg_encoding = "utf8";
 $dg_collation = "utf8_unicode_ci";
 $dgrid->setEncoding($dg_encoding, $dg_collation);
##  *** set interface language (default - English)
##  *** (en) - English     (de) - German     (se) Swedish     (hr) - Bosnian/Croatian
##  *** (hu) - Hungarian   (es) - Espanol    (ca) - Catala    (fr) - Francais
##  *** (nl) - Netherlands/"Vlaams"(Flemish) (it) - Italiano  (pl) - Polish
##  *** (ch) - Chinese     (sr) - Serbian
 $dg_language = "es";  
 $dgrid->setInterfaceLang($dg_language);
##  *** set direction: "ltr" or "rtr" (default - "ltr")
 $direction = "ltr";
 $dgrid->setDirection($direction);
##  *** set layouts: 0 - tabular(horizontal) - default, 1 - columnar(vertical) 
 $layouts = array("view"=>0, "edit"=>0, "filter"=>1);
 $dgrid->setLayouts($layouts);
##  *** set modes for operations ("type" => "link|button|image") 
##  *** "byFieldValue"=>"fieldName" - make the field to be a link to edit mode page
 $modes = array(
    "add"	 =>array("view"=>false, "edit"=>false, "type"=>"link"),
    "edit"	 =>array("view"=>false, "edit"=>false,  "type"=>"link", "byFieldValue"=>""),
    "cancel"  =>array("view"=>false, "edit"=>true,  "type"=>"link"),
    "details" =>array("view"=>false, "edit"=>false, "type"=>"link"),
    "delete"  =>array("view"=>false, "edit"=>false,  "type"=>"image")
 );
 $dgrid->setModes($modes);
##  *** allow scrolling on datagrid
/// $scrolling_option = false;
/// $dgrid->allowScrollingSettings($scrolling_option);  
##  *** set scrolling settings (optional)
/// $scrolling_width = "90%";
/// $scrolling_height = "100%";
/// $dgrid->setScrollingSettings($scrolling_width, $scrolling_height);
##  *** allow mulirow operations
 $multirow_option = false;
 $dgrid->allowMultirowOperations($multirow_option);
 $multirow_operations = array(
    "delete"  => array("view"=>false),
    "details" => array("view"=>false)
 );
 $dgrid->setMultirowOperations($multirow_operations);  
##  *** set CSS class for datagrid
##  *** "default" or "blue" or "gray" or "green" or your css file relative path with name
 $css_class = "blue";
## "embedded" - use embedded classes, "file" - link external css file
 $css_type = "embedded"; 
 $dgrid->setCssClass($css_class, $css_type);
##  *** set variables that used to get access to the page (like: my_page.php?act=34&id=56 etc.) 
/// $http_get_vars = array("act", "id");
/// $dgrid->setHttpGetVars($http_get_vars);
##  *** set other datagrid/s unique prefixes (if you use few datagrids on one page)
##  *** format (in wich mode to allow processing of another datagrids)
##  *** array("unique_prefix"=>array("view"=>true|false, "edit"=>true|false, "details"=>true|false));
 $anotherDatagrids = array("fp_"=>array("view"=>false, "edit"=>true, "details"=>true));
 $dgrid->setAnotherDatagrids($anotherDatagrids);  
##  *** set DataGrid caption

 $dg_caption = "";
// $dgrid->setCaption($dg_caption);


##
## +---------------------------------------------------------------------------+
## | 3. Printing & Exporting Settings:                                         | 
## +---------------------------------------------------------------------------+
##  *** set printing option: true(default) or false 
 $printing_option = true;
 $dgrid->allowPrinting($printing_option);
##  *** set exporting option: true(default) or false 
 $exporting_option = false;
 $dgrid->allowExporting($exporting_option);
##
##
## +---------------------------------------------------------------------------+
## | 4. Sorting & Paging Settings:                                             | 
## +---------------------------------------------------------------------------+
##  *** set sorting option: true(default) or false 
 $sorting_option = true;
 $dgrid->allowSorting($sorting_option);               
##  *** set paging option: true(default) or false 
 $paging_option = true;
 $rows_numeration = true;
 $numeration_sign = "Num";
 $dgrid->allowPaging($paging_option, $rows_numeration, $numeration_sign);
##  *** set paging settings
 $bottom_paging = array("results"=>true, "results_align"=>"left", "pages"=>true, "pages_align"=>"center", "page_size"=>true, "page_size_align"=>"right");
 $top_paging = array();

if ($_SESSION['caweb']['acceso'] >= 4)
{
 $pages_array = array("15"=>"15", "25"=>"25", "50"=>"50", "75"=>"75", "100"=>"100", "500"=>"500", "1000"=>"1000");
 $default_page_size = 25;
}
else
{
 $pages_array = array("10"=>"10");
 $default_page_size = 10;
}



 $dgrid->setPagingSettings($bottom_paging, $top_paging, $pages_array, $default_page_size);
##
##
## +---------------------------------------------------------------------------+
## | 5. Filter Settings:                                                       | 
## +---------------------------------------------------------------------------+
##  *** set filtering option: true or false(default)
 $filtering_option = false;
 $dgrid->allowFiltering($filtering_option);
##  *** set aditional filtering settings

  $filtering_fields = array(
    "Titulo"  =>array("table"=>"bitacoras", "field"=>"titulo", "source"=>$temas_array, "order"=>"DESC", "operator"=>true, "type"=>"dropdownlist", "case_sensitive"=>false,  "comparison_type"=>"binary"), 
    "Relevancia"  =>array("table"=>"bitacoras", "field"=>"relevancia", "source"=>$relevancia_array, "order"=>"ASC", "operator"=>true, "type"=>"dropdownlist", "case_sensitive"=>false,  "comparison_type"=>"binary")
  );
  $dgrid->setFieldsFiltering($filtering_fields);
##
## 
## +---------------------------------------------------------------------------+
## | 6. View Mode Settings:                                                    | 
## +---------------------------------------------------------------------------+
##  *** set view mode table properties
/// $vm_table_properties = array("width"=>"90%");
/// $dgrid->setViewModeTableProperties($vm_table_properties);  
##  *** set columns in view mode
##  *** Ex.: "on_js_event"=>"onclick='alert(\"Yes!!!\");'"
##  ***      "barchart" : number format in SELECT SQL must be equal with number format in max_value

if ($_SESSION['caweb']['tiporeporte']=="D")
{
 $vm_colimns = array(
    "interno"   =>array("header"=>"Interno_serial", "type"=>"label", "width"=>"10px","align"=>"left", "wrap"=>"wrap", "text_length"=>"-1", "case"=>"normal"),
    "ultimomovimiento"   =>array("header"=>"FechaUltimomovimiento", "type"=>"label", "width"=>"10px","align"=>"left", "wrap"=>"wrap", "text_length"=>"-1", "case"=>"normal"),
    "fechainstalacion"   =>array("header"=>"Fechainstalacion", "type"=>"label", "width"=>"10px","align"=>"left", "wrap"=>"wrap", "text_length"=>"-1", "case"=>"normal"),
    "item"   =>array("header"=>"Codigo", "type"=>"label", "width"=>"10px","align"=>"left", "wrap"=>"wrap", "text_length"=>"-1", "case"=>"normal"),
    "serial"   =>array("header"=>"Serial", "type"=>"label", "width"=>"10px","align"=>"left", "wrap"=>"wrap", "text_length"=>"-1", "case"=>"normal"),
    "descripcion"   =>array("header"=>"Descripcion", "type"=>"label", "width"=>"10px","align"=>"left", "wrap"=>"wrap", "text_length"=>"-1", "case"=>"normal"),
    "tarifa"   =>array("header"=>"Tarifa", "type"=>"label", "width"=>"10px","align"=>"left", "wrap"=>"wrap", "text_length"=>"-1", "case"=>"normal"),
    "sucursal"   =>array("header"=>"Sucursal", "type"=>"label", "width"=>"10px","align"=>"left", "wrap"=>"wrap", "text_length"=>"-1", "case"=>"normal"),
    "bodega"   =>array("header"=>"Bodega", "type"=>"label", "width"=>"10px","align"=>"left", "wrap"=>"wrap", "text_length"=>"-1", "case"=>"normal"),
    "ubicacion"   =>array("header"=>"Ubicacion", "type"=>"label", "width"=>"10px","align"=>"left", "wrap"=>"wrap", "text_length"=>"-1", "case"=>"normal"),
    "nombre"   =>array("header"=>"Nombre", "type"=>"label", "width"=>"10px","align"=>"left", "wrap"=>"wrap", "text_length"=>"-1", "case"=>"normal"),
    "ciudad"   =>array("header"=>"Ciudad", "type"=>"label", "width"=>"10px","align"=>"left", "wrap"=>"wrap", "text_length"=>"-1", "case"=>"normal"),
    "estado"   =>array("header"=>"Estado", "type"=>"label", "width"=>"10px","align"=>"left", "wrap"=>"wrap", "text_length"=>"-1", "case"=>"normal"),
    "pedido"   =>array("header"=>"Pedido", "type"=>"label", "width"=>"10px","align"=>"left", "wrap"=>"wrap", "text_length"=>"-1", "case"=>"normal"),
    "calidad"   =>array("header"=>"Calidad", "type"=>"label", "width"=>"10px","align"=>"left", "wrap"=>"wrap", "text_length"=>"-1", "case"=>"normal"),
    "memoria"   =>array("header"=>"Memoria", "type"=>"label", "width"=>"10px","align"=>"left", "wrap"=>"wrap", "text_length"=>"-1", "case"=>"normal"),
    "disco"   =>array("header"=>"Disco", "type"=>"label", "width"=>"10px","align"=>"left", "wrap"=>"wrap", "text_length"=>"-1", "case"=>"normal"),
    "video"   =>array("header"=>"Video", "type"=>"label", "width"=>"10px","align"=>"left", "wrap"=>"wrap", "text_length"=>"-1", "case"=>"normal"),
    "red"   =>array("header"=>"Red", "type"=>"label", "width"=>"10px","align"=>"left", "wrap"=>"wrap", "text_length"=>"-1", "case"=>"normal"),
    "optico"   =>array("header"=>"Optico", "type"=>"label", "width"=>"10px","align"=>"left", "wrap"=>"wrap", "text_length"=>"-1", "case"=>"normal")
  );
  $dgrid->setColumnsInViewMode($vm_colimns);
}


if ($_SESSION['caweb']['tiporeporte']=="R")
{
 $vm_colimns = array(
    "item"   =>array("header"=>"Item", "type"=>"label", "width"=>"10px","align"=>"left", "wrap"=>"wrap", "text_length"=>"-1", "case"=>"normal"),
    "descripcion"   =>array("header"=>"Descripcion","type"=>"label", "width"=>"10px","align"=>"left", "wrap"=>"wrap", "text_length"=>"-1", "case"=>"normal"),
    "cantidad"   =>array("header"=>"Cantidad","type"=>"label", "width"=>"10px","align"=>"left", "wrap"=>"wrap", "text_length"=>"-1", "case"=>"normal")
  );
  $dgrid->setColumnsInViewMode($vm_colimns);
}


##
##
## +---------------------------------------------------------------------------+
## | 7. Add/Edit/Details Mode Settings:                                        | 
## +---------------------------------------------------------------------------+
##  *** set add/edit mode table properties
// $em_table_properties = array("width"=>"70%");
// $dgrid->setEditModeTableProperties($em_table_properties);
##  *** set details mode table properties
// $dm_table_properties = array("width"=>"70%");
// $dgrid->setDetailsModeTableProperties($dm_table_properties);
##  ***  set settings for add/edit/details modes
  $table_name  = "seriales";
  $primary_key = "interno";
  $condition   = "";
  $dgrid->setTableEdit($table_name, $primary_key, $condition);
##  *** set columns in edit mode
##  *** first letter: r - required, s - simple (not required)
##  *** second letter: t - text(including datetime), n - numeric, a - alphanumeric, e - email, f - float, y - any, l - login name, z - zipcode, p - password, i - integer, v - verified
##  *** third letter (optional): 
##          for numbers: s - signed, u - unsigned, p - positive, n - negative
##          for strings: u - upper,  l - lower,    n - normal,   y - any
##  *** Ex.: "on_js_event"=>"onclick='alert(\"Yes!!!\");'"
##  *** Ex.: type = textbox|textarea|label|date(yyyy-mm-dd)|datedmy(dd-mm-yyyy)|datetime(yyyy-mm-dd hh:mm:ss)|datetimedmy(dd-mm-yyyy hh:mm:ss)|image|password|enum|print|checkbox
##  *** make sure your WYSIWYG dir has 755 permissions

  $em_columns = array(
      "relevancia" =>array("header"=>"Relevancia", "type"=>"enum",   "source"=>$relevancia_array,"view_type"=>"dropdownlist", "width"=>"139px", "req_type"=>"sy", "title"=>"Relevancia"),
      "tarea"     =>array("header"=>"Tarea",      "type"=>"textbox",  "width"=>"210px", "req_type"=>"sy", "title"=>"Tarea", "unique"=>false),
      "avance"    =>array("header"=>"Avance", "type"=>"enum", "source"=>$avance_array,"view_type"=>"dropdownlist", "width"=>"139px", "req_type"=>"sy", "title"=>"Avance"),  
      "titulo"    =>array("header"=>"Titulo", "type"=>"enum","source"=>$temas_array,"view_type"=>"dropdownlist", "width"=>"139px", "req_type"=>"sy", "title"=>"Avance"),
      "proyecto"  =>array("header"=>"Proyecto",  "type"=>"textbox",  "width"=>"310px", "req_type"=>"sy", "title"=>"Proyecto", "unique"=>false),
      "descripcion" =>array("header"=>"Descripcion", "type"=>"textarea", "width"=>"210px", "req_type"=>"sy", "title"=>"Descripcion", "edit_type"=>"wysiwyg", "rows"=>"15", "cols"=>"90")

//    "is_democracy"     =>array("header"=>"Is Democracy", "type"=>"checkbox", "true_value"=>1, "false_value"=>0,  "width"=>"210px", "req_type"=>"sy", "title"=>"Is Democraty"),
//    "independent_date" =>array("header"=>"Independence Day", "type"=>"date",     "width"=>"210px", "req_type"=>"rt", "title"=>"Independence Day")
  );
  $dgrid->setColumnsInEditMode($em_columns);
##  *** set auto-genereted columns in edit mode
//  $auto_column_in_edit_mode = false;
//  $dgrid->setAutoColumnsInEditMode($auto_column_in_edit_mode);
##  *** set foreign keys for add/edit/details modes (if there are linked tables)
##  *** Ex.: "condition"=>"TableName_1.FieldName > 'a' AND TableName_1.FieldName < 'c'"
##  *** Ex.: "on_js_event"=>"onclick='alert(\"Yes!!!\");'"
// $foreign_keys = array(
//    "region_id"=>array("table"=>"regions", "field_key"=>"id","field_name"=>"name", "view_type"=>"dropdownlist", "order_by_field"=>"name", "order_type"=>"ASC")
// );
// $dgrid->setForeignKeysEdit($foreign_keys);

 ################################################################################


?>

<html>
<head>
    <title>PC COM S.A.</title>
    <meta http-equiv=Content-Type content="text/html; charset=utf-8">
    <link rel="stylesheet" type="text/css" media="screen" href="css/caweb.css" />
    <?
        ## call of this method between HTML <HEAD> elements
         $dgrid->WriteCssClass();
    ?>
</head>
<center><b><h3> CONSULTA DE INVENTARIO DE EQUIPOS </h3></b></center>
<center><b><h4><font color="blue"> ** NO incluye Bodega BAJAS ** </font></h4></b></center>
<body>
<?


setlocale(LC_ALL,'es_ES');
echo strftime("%A, %d %B %Y")." ".date("g:i a")."<br>";

echo "<br><h3><a href=\"javascript:location.href='../consultainventario.php'\">Regresar...</a></h3>";
echo "<b>Condicion: </b>".$condicion;

    ################################################################################   
    ## +---------------------------------------------------------------------------+
    ## | 8. Bind the DataGrid:                                                     | 
    ## +---------------------------------------------------------------------------+
    ##  *** bind the DataGrid and draw it on the screen
      $dgrid->Bind();
      ob_end_flush();
    ################################################################################   




if ($_SESSION['caweb']['acceso'] >= 4 OR $_SESSION['caweb']['username']=='jefedefacturacion')
{ 
    if ($_SESSION['caweb']['acceso'] == 10 OR $_SESSION['caweb']['username']=='jefedefacturacion')
    {
        echo "<font size='5'><a href='exportar.php'>Exportar</a></font>";
    }
    
	echo "<br><font style='font-size:12px' color='#000000' face='Arial'>RESUMEN POR CLASE:</font><br>";
	$link53 = con_caweb();

	$result53 ="
	SELECT 
	COUNT( seriales.interno ) AS total, 
	SUM( seriales.tarifa ) AS valor,
	scla.descripcionsubclase AS tipo
	FROM seriales
	INNER JOIN intranetpccom.taxonomia tax ON tax.codigotaxonomia = seriales.item
	LEFT JOIN intranetpccom.subclases scla ON scla.codigosubclases = tax.codigosubclases and scla.codigoclase = tax.codigoclase
	WHERE  left(tax.codigotaxonomia,1) in ('C','I','M','O') $condicion
	GROUP BY scla.codigosubclases";

	echo "<table border=1><tr bgcolor='#aabbcc'><td><b>Clase</b><td><b>Cantidad</b><td><b>Tarifa</b><td><b>Promedio</b></tr>";
	$result53=mysql_query($result53,$link53) or die('Error seriales1, '.mysql_error());
	while($row53 = mysql_fetch_array($result53))
	{
	        echo "<tr><td>".$row53[tipo]."<td align='center'>".number_format($row53[total],0,",",",")."<td>".number_format($row53[valor],0,",",",")
			."<td>".number_format(($row53[valor]/$row53[total]),0,",",",");
	}

	$result53 ="
	SELECT 
	COUNT( seriales.interno ) AS total, 
	SUM( seriales.tarifa ) AS valor
	FROM seriales
	WHERE 1=1 AND (LEFT(item,1)='C' OR LEFT(item,1)='I') $condicion";
	$result53=mysql_query($result53,$link53) or die('Error seriales2, '.mysql_error());
	$row53 = mysql_fetch_array($result53);
 	echo "<tr bgcolor='#ccddee'><td>Total CAT + IMP<td align='center'>".number_format($row53[total],0,",",",")."<td>".number_format($row53[valor],0,",",",")
			."<td>".number_format(($row53[valor]/$row53[total]),0,",",",");
	echo "</table>";
	

	echo "<br><font style='font-size:12px' color='#000000' face='Arial'>RESUMEN GENERAL: </font><br>";
	$link53 = con_caweb();
	$result53 ="
	SELECT if( LEFT( item, 1 )='C', 'CPU',
	if( LEFT( item, 1 )='M', 'MON',
	if( LEFT( item, 1 )='I', 'IMPR',
	if( LEFT( item, 1 )='O', 'OTROS',
	LEFT( item, 1 ) )))) AS tipo,
	COUNT( interno ) AS total
	FROM seriales
	WHERE 1=1 $condicion
	GROUP BY tipo";

	$result53=mysql_query($result53,$link53) or die('Error seriales3, '.mysql_error());
	while($row53 = mysql_fetch_array($result53))
	{
	        echo $row53[tipo]." = ". $row53[total]."  ,  ";
	}
	
	echo "</font>";
}


?>
</body>
</html>
